package L621;

/**
 * @program: javase
 * @description: 不含重复元素
 * @author: luolidong
 * @create: 2021-06-21 17:19
 * @version: 1.0
 */
 public class Demo {
//    3 4 5 6 7 8 0 1 2

    /**
     * 时间复杂度为循环的次数
     * 二分查找时间复杂度：logn
     * n n/2 n/4 n/2^k k为循环次数
     * n/2^k=1,k=logn
     */
    public int findMin(int[] nums) {
        int l = 0, r = nums.length - 1;
        while (l < r) {
            int mid = (l + r) / 2;
            if (nums[mid] > nums[r]) {
                l = mid + 1;
            } else {
                r = mid;
            }
        }
        return nums[l];
    }

    public static void main(String[] args) {
//        int min = new Demo().findMin(new int[]{3,3,3,3,1,3,3});
        int min1 = new Demo().findMin(new int[]{1, 2, 3, 4});
        System.out.println(min1);
    }
 }
